const moment = require('moment');
const jwt = require('jsonwebtoken');
const utilTool = require('../../util');
const $config = require('../../config');

module.exports = {
  accessList: async (ctx, next) => {
    $config.documents = 'accessList' // 切换文档集合
    const token = ctx.request.header.token;
    await jwt.verify(token, $config.tokenSecret, async (err, resultToken) => { // resultToken 解析token值
      if (err) {  //  时间失效的时候/ 伪造的token
        ctx.body = {
          success: false,
          result: '验证已过期！',
          ...err
        };
        return;
      }
      const access = await utilTool.findMany({}, {_id:0}, {});
      ctx.body = {
        success: true,
        result: access[0]
      };
    })
  }
};
